// pages/stumessage/stumessage.js
const app = getApp()
const db = wx.cloud.database();

Page({
    
  data: {
    name: '',
    id:'',
    sex:'',
    class1:'',
    college:'',
    
  },

  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onShow: function () {
    // 生命周期函数--监听页面显示
    wx.hideTabBar({})
  },
  onLoad: function () {
   
  },
 
 
  // 获取输入姓名
  nameInput: function (e) {
    this.setData({
      name: e.detail.value
    })
  },
  // 获取输入性别
  sexInput: function (e) {
    this.setData({
      sex: e.detail.value
    })
  },
  // 获取输入学院
  collegeInput: function (e) {
    this.setData({
      college: e.detail.value
    })
  },

  // 获取输入工号
  idInput: function (e) {
    this.setData({
      id: e.detail.value
    })
  },

  // 登录处理
  login: function (e) {
    var that = this;
    if (this.data.name.length == 0 || this.data.sex.length == 0 || this.data.college.length == 0 || this.data.id.length == 0) {
      wx.showToast({
        title: '填写信息不能为空',
        icon: 'none',
        duration: 2000
      })
    } else {
        db.collection('teacher').add({
            data:{
                name:this.data.name,
                sex:this.data.sex,
                college:this.data.college,
                // class1:this.data.class1,
                id:this.data.id
            }
        })
        wx.requestSubscribeMessage({
            tmplIds: ['NjDke6Kr2lK3cvl2IN-fYKnQQRYmg0mcAPJP6vND1KU','ij2BMWtsIYCo0Eh5imXbvwZ18Drw1SK01-U1mJzLs54','6BIiBaizcaSGRChSi_rx56zDBXGTGAaOxXddfZk8U0A'],
            success(res){
                console.log('授权成功',res)
            },
            fail(res){
                console.log('授权失败',res)
            }
        })
        wx.switchTab({
          url: '/pages/function/function',
        })
    }
  }
})